/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa_jai;

import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.Histogram;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author thay
 */
public class Histograma {

    private ParameterBlock pb1, pb2;
    private PlanarImage modelo1, modelo2;
    private Histogram histograma1, histograma2;

    public Histograma(PlanarImage imagem) {

        // Gerando primeiro histograma com 32 bins...
        pb1 = new ParameterBlock();
        pb1.addSource(imagem);
        pb1.add(null);
        pb1.add(1);
        pb1.add(1);
        pb1.add(new int[]{32});   // Quantidade de barras do histograma;
        pb1.add(new double[]{0});
        pb1.add(new double[]{256});

        modelo1 = JAI.create("histogram", pb1);
        histograma1 = (Histogram) modelo1.getProperty("histogram");

        // Gerando primeiro histograma com 256 bins...
        pb2 = new ParameterBlock();
        pb2.addSource(imagem);
        pb2.add(null);
        pb2.add(1);
        pb2.add(1);
        pb2.add(new int[]{256});
        pb2.add(new double[]{0});
        pb2.add(new double[]{256});

        modelo2 = JAI.create("histogram", pb2);
        histograma2 = (Histogram) modelo2.getProperty("histogram");
    }

    public Histogram getHistograma(int i) {

        switch (i) {
            case 32:
                return histograma1;
            case 256:
                return histograma2;
        }
        return null;
    }
}

